package cn.tedu.api;

import java.util.Arrays;

/*字符串拼接*/
public class TestString3 {
    public static void main(String[] args) {
        String s="abcdefghijklmnopqrstuvwxyz";
       // method1(s);
        System.out.println("_________________________________");
       method2(s);
        System.out.println("_________________________________");
       // method3(s);

    }

    private static void method3(String s) {
        String result="";
        long t1=System.currentTimeMillis();

        for(int i=1;i<=10000;i++){
            result=result.concat(s);
        }
        long t2=System.currentTimeMillis();
        System.out.println(result);
        System.out.println(t2-t1);
    }

    private static void method2(String s) {

        StringBuffer sb=new StringBuffer();
        StringBuilder sb2=new StringBuilder();
        long t1=System.currentTimeMillis();

        for(int i=1;i<=10000;i++){
            sb2.append(s);
        }
        long t2=System.currentTimeMillis();
        System.out.println(sb2);

        System.out.println(t2-t1);
    }

    private static void method1(String s) {
        String result="";
        long t1=System.currentTimeMillis();
        for(int i=1;i<=10000;i++){
            result=result+s;
        }
        long t2=System.currentTimeMillis();
        System.out.println(result);
        System.out.println(t2-t1);
    }
}
